package org.discala.util.logging

/**
 * Simple logger implementation that just outputs everything to the console.
 * Intended to be used during development and testing where the need to see logging
 * is important but the full set of logging configuration options are not required.
 *
 * @author Chris Turner
 */
trait ConsoleLogger extends Logged with LoggerUtils {

  import LogLevel._

  def trace(message: String, values: Any*) = log(Trace, message, values.toList)

  def trace(message: String, error: Throwable) = log(Trace, message, error)

  def debug(message: String, values: Any*) = log(Debug, message, values.toList)

  def debug(message: String, error: Throwable) = log(Debug, message, error)

  def info(message: String, values: Any*) = log(Info, message, values.toList)

  def info(message: String, error: Throwable) = log(Info, message, error)

  def warn(message: String, values: Any*) = log(Warn, message, values.toList)

  def warn(message: String, error: Throwable) = log(Warn, message, error)

  def error(message: String, values: Any*) = log(Error, message, values.toList)

  def error(message: String, error: Throwable) = log(Error, message, error)

  def log(level: LogLevel, message: String, params: List[Any]) =
    System.out.println(asString(level) + " " + parameteriseMessage(message, params))

  def log(level: LogLevel, message: String, error: Throwable) = {
    System.out.println(asString(level) + " " + message)
    error.printStackTrace(System.out)
  }
}
